package com.atguigu.tingshu.user.strategy;
import java.util.Date;
import com.google.common.collect.Maps;

import com.atguigu.tingshu.common.execption.GuiguException;
import com.atguigu.tingshu.model.user.UserPaidAlbum;
import com.atguigu.tingshu.user.mapper.UserPaidAlbumMapper;
import com.atguigu.tingshu.vo.user.UserPaidRecordVo;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

@Component(value = "1001")
@Slf4j
public class ProcessAlbumOrderTypePayRecord implements ProcessDiffPayRecord{
    @Autowired
    private UserPaidAlbumMapper userPaidAlbumMapper;

    /**
     * 处理专辑订单类型支付记录
     * @param userPaidRecordVo 支付记录
     */
    @Override
    public void processPayRecord(UserPaidRecordVo userPaidRecordVo) {
        // user_paid_album表中插入数据
        String orderNo = userPaidRecordVo.getOrderNo();
        Long count = userPaidAlbumMapper.selectCount(new LambdaQueryWrapper<UserPaidAlbum>().eq(UserPaidAlbum::getOrderNo, orderNo));
        if (count != 0){
            throw new GuiguException(201, "该专辑类型订单支付流水以存在");
        }
        UserPaidAlbum userPaidAlbum = new UserPaidAlbum();
        userPaidAlbum.setOrderNo(orderNo);
        userPaidAlbum.setUserId(userPaidRecordVo.getUserId());
        userPaidAlbum.setAlbumId(userPaidRecordVo.getItemIdList().get(0));
        int insert = userPaidAlbumMapper.insert(userPaidAlbum);
        log.info("保存订单：{}，记录支付流水:{}",orderNo,insert > 0 ? "success":"fail");
    }
}
